package com.hzyb.shopHotSearch.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.hzyb.shopHotSearch.dao.ShopHotSearchDao;
import com.hzyb.shopHotSearch.model.ShopHotSearch;
import com.hzyb.shopHotSearch.service.ShopHotSearchService;
@Service
public class ShopHotSearchServiceImpl implements ShopHotSearchService{

	@Autowired
	private ShopHotSearchDao ShopHotSearchDao;

	@Override
	public List<ShopHotSearch> changeHotSearch(String index) {
		List<String> list=ShopHotSearchDao.getAllIndex();
		Sort sort=new Sort(Sort.DEFAULT_DIRECTION.DESC,"index");
		if(index.equals("-1")) {
			return ShopHotSearchDao.findByIndex(list.get(0),sort);
		}
		if(index.equals(list.get(list.size()-1))) {
			return ShopHotSearchDao.findByIndex(list.get(0),sort);
		}
		for(int i=0;i<list.size();i++) {
			if(list.get(i).equals(index)) {
				return ShopHotSearchDao.findByIndex(list.get(i+1),sort);
			}
		}
		return null;
	}

}
